﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace ListView控件
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            List<User> userlist = new List<User>();
            for(int i=1; i<100; i++)
            {
                User user1 = new User();
                user1.UserName = "name_" + i.ToString();
                user1.UserAdress = "supermark_" + i.ToString();
                user1.UsreYear = i.ToString();
                user1.UserShocl = "Harval_" + i.ToString();
                userlist.Add(user1);
            }

            this.listView.ItemsSource = userlist;

        }

        bool isEdit = false;
        private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
        {
            Grid grid = sender as Grid;
            TextBlock texblock1 = grid.Children[0] as TextBlock;
            TextBox textbox1 = grid.Children[1] as TextBox;

            texblock1.Visibility = Visibility.Hidden;
            textbox1.Visibility = Visibility.Visible;

            isEdit = true;
        }

        private void Grid_MouseLeave(object sender, MouseEventArgs e)
        {
            if (isEdit)
            {
                Grid grid = sender as Grid;
                TextBlock texblock1 = grid.Children[0] as TextBlock;
                TextBox textbox1 = grid.Children[1] as TextBox;

                texblock1.Visibility = Visibility.Visible;
                textbox1.Visibility = Visibility.Hidden;
                List<User> userList = (List<User>)this.listView.ItemsSource;

                isEdit = false;
            }


        }
    }


    public class User
    {
        public string UserName { get; set; }
        public string UserAdress { get; set; }
        public string UsreYear { get; set; }
        public string UserShocl { get; set; }
    }
}
